package com.myapplication.ui.listfragment.shoplistactivity.pinglun;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.myapplication.R;
import com.myapplication.bean.CommentBean;
import com.myapplication.utils.CropCircleTransformation;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by My on 2016/10/20.
 */
public class CommentRVAdapter extends RecyclerView.Adapter<CommentRVAdapter.MyViewHolder> {
    private Context context;
    private List<CommentBean.DataBean.CommentsBean> commentlist;
    public CommentRVAdapter(Context context,List<CommentBean.DataBean.CommentsBean> commentlist){
        this.context=context;
        this.commentlist=commentlist;
        Log.i("TAG","WOSHI ADAPTER----------");
    }

//    public CommentRVAdapter(){
//
//    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder=new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_comment,null));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tv_comment_content.setText(commentlist.get(position).getCommentContent());
        holder.tv_comment_nickname.setText(commentlist.get(position).getUser().getNickname());
//        holder.tv_comment_time.setText(commentlist.get(position).getPubTime());
        String imageurl=commentlist.get(position).getUser().getPhoto();
        Log.i("TAG", "--------->onBindViewHolder: "+imageurl);
        Picasso.with(context).load(imageurl).transform(new CropCircleTransformation()).into(holder.iv_comment_image);
    }

    @Override
    public int getItemCount() {
        Log.i("TAG", "------------->getItemCount: "+commentlist.size());
        return commentlist.size();

    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView iv_comment_image;
        TextView tv_comment_nickname,tv_comment_content,tv_comment_time;

        public MyViewHolder(View itemView) {
            super(itemView);
            iv_comment_image= (ImageView) itemView.findViewById(R.id.iv_comment_image);
            tv_comment_nickname= (TextView) itemView.findViewById(R.id.tv_comment_nickname);
            tv_comment_content= (TextView) itemView.findViewById(R.id.tv_comment_content);
            tv_comment_time= (TextView) itemView.findViewById(R.id.tv_comment_time);

        }
    }
}
